home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / facilis2.arc / TEST.PAS < prev   
Pascal/Delphi Source File  |  1991-04-28  |  22KB  |  1,005 lines

  1. program test(input,output);
  2.  
  3. {    Pascal Compiler Test Program
  4.      Version 1.31
  5.  
  6.      Written by John R. Naleszkiewicz
  7.      Date: October 19, 1984
  8.    Update: January 15, 1985
  9.              August 5, 1985
  10.             August 16, 1985      }
  11.  
  12. const
  13.      start = 10;
  14.      finish = 50;
  15.      version = 1.31;
  16.  
  17. type
  18.      rec = record
  19.              f1 : integer;
  20.              f2 : real;
  21.              f3 : boolean;
  22.              f4 : array[1 .. 3] of char;
  23.            end;
  24.  
  25. var
  26.    a,i,j : integer;
  27.    e,x,y : real;
  28.      b,f : boolean;
  29.      c,h : char;
  30.      ain : array[0 .. 10] of integer;
  31.      arl : array[start .. finish] of real;
  32.      abl : array[-5 .. 5] of boolean;
  33.      ach : array[1 .. 25] of char;
  34.  in1,in2 : array[-2 .. 8] of integer;
  35.  rl1,rl2 : array[-2 .. 8] of real;
  36.  bl1,bl2 : array[-2 .. 8] of boolean;
  37.  ch1,ch2 : array[-2 .. 8] of char;
  38.   errors : integer;
  39.  
  40.      alist,blist : rec;
  41.  
  42.  
  43. procedure ptest1;
  44. var
  45.   i : integer;
  46.   x : real;
  47.   begin
  48.     writeln('called');
  49.     i := -10;
  50.     x := -15.0
  51.   end; { ptest1 }
  52.  
  53. procedure ptest2(i : integer; x : real; var j : integer; var y : real);
  54.   begin
  55.     writeln('called');
  56.     if i<>10 then
  57.       begin
  58.         writeln('*** Call by value integer passed incorrectly (P)');
  59.         errors := errors+1;
  60.       end;
  61.     if x<>10.0 then
  62.       begin
  63.         writeln('*** Call by value real passed incorrectly (P)');
  64.         errors := errors+1;
  65.       end;
  66.     if j<>25 then
  67.       begin
  68.         writeln('*** Call by reference integer passed incorrectly (P)');
  69.         errors := errors+1;
  70.       end;
  71.     if y<>25.0 then
  72.       begin
  73.         writeln('*** Call by reference real passed incorrectly (P)');
  74.         errors := errors+1;
  75.       end;
  76.     j := j - 1;
  77.     y := y - 1.0
  78.   end; { ptest2 }
  79.  
  80. procedure ptest3(i : integer);
  81.   begin
  82.     write(i:1);
  83.     if i>0 then
  84.       ptest3(i-1)
  85.   end; { ptest3 }
  86.  
  87. function ftest1(k : integer; z : real): integer;
  88.   begin
  89.     writeln('called');
  90.     if k<>0 then
  91.       begin
  92.         writeln('*** Call by value integer passed incorrectly (F)');
  93.         errors := errors+1;
  94.       end;
  95.     if z<>75.0 then
  96.       begin
  97.         writeln('*** Call by value real passed incorrectly (F)');
  98.         errors := errors+1;
  99.       end;
  100.     ftest1 := 100
  101.   end; { ftest1 }
  102.  
  103. function ftest2(m : integer): integer;
  104.   begin
  105.     if m>0 then
  106.       ftest2 := ftest2(m-1) + 2
  107.     else
  108.       ftest2 := 0;
  109.     write(m:1)
  110.   end; { ftest2 }
  111.  
  112.  
  113. begin  { main program }
  114.   writeln;
  115.   writeln('  Pascal Compiler Test Program -- Version ',version:4:2);
  116.   writeln;
  117.  
  118.   errors := 0;
  119.   writeln('If statement and logical tests (P=pass, F=fail)');
  120.   write('  Simple logical test (PP):');
  121.   if true then
  122.     write('P')
  123.   else
  124.     write('F');
  125.   if false then
  126.     writeln('F')
  127.   else
  128.     writeln('P');
  129.   write('  Logical NOT test (PP):');
  130.   if not true then
  131.     write('F')
  132.   else
  133.     write('P');
  134.   if not false then
  135.     writeln('P')
  136.   else
  137.     writeln('F');
  138.   write('  Logical AND test (PPP):');
  139.   if true and true then
  140.     write('P')
  141.   else
  142.     write('F');
  143.   if true and false then
  144.     write('F')
  145.   else
  146.     write('P');
  147.   if false and false then
  148.     writeln('F')
  149.   else
  150.     writeln('P');
  151.   write('  Logical OR test (PPP):');
  152.   if true or true then
  153.     write('P')
  154.   else
  155.     write('F');
  156.   if true or false then
  157.     write('P')
  158.   else
  159.     write('F');
  160.   if false or false then
  161.     writeln('F')
  162.   else
  163.     writeln('P');
  164.   write('  Logical comparison tests = <> < > <= >= (PPPPPPPP):');
  165.   if 10 = 10 then
  166.     write('P')
  167.   else
  168.     write('F');
  169.   if 10 <> 1 then
  170.     write('P')
  171.   else
  172.     write('F');
  173.   if 1 < 10 then
  174.     write('P')
  175.   else
  176.     write('F');
  177.   if 10 > 1 then
  178.     write('P')
  179.   else
  180.     write('F');
  181.   if 10 <= 10 then
  182.     write('P')
  183.   else
  184.     write('F');
  185.   if 1 <= 10 then
  186.     write('P')
  187.   else
  188.     write('F');
  189.   if 10 >= 10 then
  190.     write('P')
  191.   else
  192.     write('F');
  193.   if 10 >= 1 then
  194.     writeln('P')
  195.   else
  196.     writeln('F');
  197.  
  198.   writeln;
  199.   write('   Enter "C" <return> to continue');
  200.   read(c);
  201.   writeln;
  202.   writeln;
  203.  
  204.   writeln('  Variable assignment tests');
  205.   writeln('    Simple variable assignment tests');
  206.   i := 10;
  207.   writeln('    Integer stored:    10, contents: ',i:3);
  208.   j := i;
  209.   if j<>10 then
  210.     begin
  211.       write('*** Integer assignment test failed, ');
  212.       writeln(j,' instead of 10');
  213.       errors := errors+1;
  214.     end;
  215.  
  216.   j := -i;
  217.   writeln('    Integer stored:   -10, contents: ',j:3);
  218.   if j<>-10 then
  219.     begin
  220.       write('*** Integer negation test failed, ');
  221.       writeln(j,' instead of -10');
  222.       errors := errors+1;
  223.     end;
  224.  
  225.   x := 10.0;
  226.   writeln('    Real stored:  1.0000E+01, contents:',x);
  227.   y := x;
  228.   if y<>10.0 then
  229.     begin
  230.       write('*** Floating point assignment failed, ');
  231.       writeln(y,' instead of 1.0000E+01');
  232.       errors := errors+1;
  233.     end;
  234.  
  235.   y := -x;
  236.   writeln('    Real stored: -1.0000E+01, contents:',y);
  237.   if y<>-10.0 then
  238.     begin
  239.       write('*** Floating point negation failed, ');
  240.       writeln(y,' instead of -1.0000E+01');
  241.       errors := errors+1;
  242.     end;
  243.  
  244.   b := true;
  245.   f := b;
  246.   if not f then
  247.     begin
  248.       write('*** Boolean assignment (true) failed, ');
  249.       writeln('false instead of true');
  250.       errors := errors+1;
  251.     end;
  252.  
  253.   b := false;
  254.   f := b;
  255.   if f then
  256.     begin
  257.       write('*** Boolean assignment (false) failed, ');
  258.       writeln('true instead of false');
  259.       errors := errors+1;
  260.     end;
  261.  
  262.   c := 'x';
  263.   h := c;
  264.   if h<>'x' then
  265.     begin
  266.       write('*** Character assignment failed, ');
  267.       writeln('result of "',h,'" instead of "x"');
  268.       errors := errors+1;
  269.     end;
  270.  
  271.  
  272.   writeln('    Array assignment tests');
  273.   ain[0] := 25;
  274.   ain[5] := ain[0];
  275.   if ain[5]<>25 then
  276.     begin
  277.       write('*** Integer array assignment failed, ');
  278.       writeln(ain[5],' instead of 25');
  279.       errors := errors+1;
  280.     end;
  281.  
  282.   arl[25] := 1000.0;
  283.   arl[45] := arl[25];
  284.   if arl[45]<>1000.0 then
  285.     begin
  286.       write('*** Floating point array assignment failed, ');
  287.       writeln(arl[45],' instead of 1.0000E+03');
  288.       errors := errors+1;
  289.     end;
  290.  
  291.   abl[-3] := true;
  292.   abl[3]  := abl[-3];
  293.   if not abl[3] then
  294.     begin
  295.       write('*** Boolean array assignment (true) failed, ');
  296.       writeln('false instead of true');
  297.       errors := errors+1;
  298.     end;
  299.  
  300.   abl[0] := false;
  301.   abl[5] := abl[0];
  302.   if abl[5] then
  303.     begin
  304.       write('*** Boolean array assignment (false) failed, ');
  305.       writeln('true instead of false');
  306.       errors := errors+1;
  307.     end;
  308.  
  309.   ach[10] := 'a';
  310.   ach[23] := ach[10];
  311.   if ach[23]<>'a' then
  312.     begin
  313.       write('*** Character array assignment failed, ');
  314.       writeln('result of "',ach[23],'" instead of "a"');
  315.       errors := errors+1;
  316.     end;
  317.  
  318.  
  319.   writeln('    Block Array assignment tests');
  320.   for i:=-2 to 8 do
  321.     begin
  322.       in1[i] := i*3;
  323.       rl1[i] := i*2.0;
  324.       if odd(i) then
  325.         bl1[i] := true
  326.       else
  327.         bl1[i] := false;
  328.       ch1[i] := chr(i+67);
  329.     end;
  330.   in2 := in1;
  331.   rl2 := rl1;
  332.   bl2 := bl1;
  333.   ch2 := ch1;
  334.  
  335.   for i:=-2 to 8 do
  336.     begin
  337.       if in1[i]<>i*3 then
  338.        begin
  339.          write('*** Block Integer array assignment failed, ');
  340.          writeln('at position ',i);
  341.          errors := errors+1;
  342.        end;
  343.  
  344.       if rl1[i]<>i*2.0 then
  345.         begin
  346.           write('*** Block Real array assignment failed, ');
  347.           writeln('at position ',i);
  348.           errors := errors+1;
  349.         end;
  350.  
  351.       if odd(i) then
  352.         if bl1[i]<>true then
  353.           begin
  354.             write('*** Block Boolean array assignment failed, ');
  355.             writeln('at position ',i);
  356.             errors := errors+1;
  357.           end
  358.         else
  359.       else
  360.         if bl1[i]<>false then
  361.           begin
  362.             write('*** Block Boolean array assignment failed, ');
  363.             writeln('at position ',i);
  364.             errors := errors+1;
  365.           end;
  366.      if ch1[i]<>chr(i+67) then
  367.         begin
  368.           write('*** Block Character array assignment failed, ');
  369.           writeln('at position ',i);
  370.           errors := errors+1;
  371.         end;
  372.  
  373.     end;
  374.  
  375.  
  376.   writeln('    Record field assignment tests');
  377.   alist.f1 := 99;
  378.   alist.f2 := 12.5;
  379.   alist.f3 := true;
  380.   alist.f4[1] := 'a';
  381.   alist.f4[2] := 'b';
  382.   alist.f4[3] := alist.f4[1];
  383.   blist := alist;
  384.   if blist.f1<>99 then
  385.     begin
  386.       write('*** Integer field assignment failed, ');
  387.       writeln(blist.f1,' instead of 99');
  388.       errors := errors+1;
  389.     end;
  390.  
  391.   if blist.f2<>12.5 then
  392.     begin
  393.       write('*** Real field assignment failed, ');
  394.       writeln(blist.f2,' instead of 1.2500E+01');
  395.       errors := errors+1;
  396.     end;
  397.  
  398.   if not blist.f3 then
  399.     begin
  400.       write('*** Boolean field assignment failed, ');
  401.       writeln('false instead of true');
  402.       errors := errors+1;
  403.     end;
  404.  
  405.   if blist.f4[3]<>'a' then
  406.     begin
  407.       write('*** Character array field assignment failed, ');
  408.       writeln('result of "',blist.f4[3],'" instead of "a"');
  409.       errors := errors+1;
  410.     end;
  411.  
  412.  
  413.   writeln('  Builtin function tests');
  414.   i := 3;
  415.   if not odd(i) then
  416.     begin
  417.       write('*** Function odd(x) failed, ');
  418.       writeln(i,' was found to be even');
  419.       errors := errors+1;
  420.     end;
  421.  
  422.   i := 4;
  423.   if odd(i) then
  424.     begin
  425.       write('*** Function odd(x) failed, ');
  426.       writeln(i,' was found to be odd');
  427.       errors := errors+1;
  428.     end;
  429.  
  430.   x := 1.77;
  431.   i := round(x);
  432.   j := trunc(x);
  433.   if i<>2 then
  434.     begin
  435.       write('*** Function round(x) failed, ');
  436.       writeln(i,' instead of 2');
  437.       errors := errors+1;
  438.     end;
  439.   if j<>1 then
  440.     begin
  441.       write('*** Function trunc(x) failed, ');
  442.       writeln(i,' instead of 1');
  443.       errors := errors+1;
  444.     end;
  445.  
  446.   i := -25;
  447.   j := abs(i);
  448.   if j <> 25 then
  449.     begin
  450.       write('*** Function abs(integer) failed, ');
  451.       writeln(j,' instead of 25');
  452.       errors := errors+1;
  453.     end;
  454.  
  455.   i := 99;
  456.   j := abs(i);
  457.   if j <> 99 then
  458.     begin
  459.       write('*** Function abs(integer) failed, ');
  460.       writeln(j,' instead of 99');
  461.       errors := errors+1;
  462.     end;
  463.  
  464.   x := -12.5;
  465.   y := abs(x);
  466.   if y <> 12.5 then
  467.     begin
  468.       write('*** Function abs(real) failed, ');
  469.       writeln(y,' instead of 1.2500E+01');
  470.       errors := errors+1;
  471.     end;
  472.  
  473.   x := 112.5;
  474.   y := abs(x);
  475.   if y <> 112.5 then
  476.     begin
  477.       write('*** Function abs(real) failed, ');
  478.       writeln(y,' instead of 1.1250E+02');
  479.       errors := errors+1;
  480.     end;
  481.  
  482.   i := 7;
  483.   j := sqr(i);
  484.   if j <> 49 then
  485.     begin
  486.       write('*** Function sqr(integer) failed, ');
  487.       writeln(j,' instead of 49');
  488.       errors := errors+1;
  489.     end;
  490.  
  491.   x := 5.0;
  492.   y := sqr(x);
  493.   if y <> 25.0 then
  494.     begin
  495.       write('*** Function sqr(real) failed, ');
  496.       writeln(y,' instead of 2.5000E+01');
  497.       errors := errors+1;
  498.     end;
  499.  
  500.   x := 729.0;
  501.   y := sqrt(x);
  502.   if y <> 27.0 then
  503.     begin
  504.       write('*** Function sqrt(x) failed, ');
  505.       writeln(y,' instead of 2.7000E+01');
  506.       errors := errors+1;
  507.     end;
  508.  
  509.   c := 'x';
  510.   i := ord(c);
  511.   h := chr(i);
  512.   if i<>120 then
  513.     begin
  514.       write('*** Function ord(x) failed, ');
  515.       writeln(i,' instead of 120');
  516.       errors := errors+1;
  517.     end;
  518.   if h<>'x' then
  519.     begin
  520.       write('*** Function chr(x) failed, ');
  521.       writeln('"',h,'" instead of "x"');
  522.       errors := errors+1;
  523.     end;
  524.  
  525.   i := 10;
  526.   j := succ(i);
  527.   if j<>11 then
  528.     begin
  529.       write('*** Function succ(x) failed, ');
  530.       writeln(j,' instead of 11');
  531.       errors := errors+1;
  532.     end;
  533.  
  534.   i := 99;
  535.   j := pred(i);
  536.   if j<>98 then
  537.     begin
  538.       write('*** Function pred(x) failed, ');
  539.       writeln(j,' instead of 98');
  540.       errors := errors+1;
  541.     end;
  542.  
  543.  
  544.  
  545.   writeln('  Arithmetic tests');
  546.   writeln('    Integer arithmetic tests');
  547.   i := 5 + 5;
  548.   j := i + 10;
  549.   j := j + i;
  550.   if j<>30 then
  551.     begin
  552.       write('*** Addition failed, ');
  553.       writeln(j,' instead of 30');
  554.       errors := errors+1;
  555.     end;
  556.  
  557.   i := 20 - 8;
  558.   j := i - 10;
  559.   j := i - j;
  560.   if j<>10 then
  561.     begin
  562.       write('*** Subtraction failed, ');
  563.       writeln(j,' instead of 10');
  564.       errors := errors+1;
  565.     end;
  566.  
  567.   i := 2 * 3;
  568.   j := i * 4;
  569.   j := j * i;
  570.   if j<>144 then
  571.     begin
  572.       write('*** Multiplication failed, ');
  573.       writeln(j,' instead of 144');
  574.       errors := errors+1;
  575.     end;
  576.  
  577.   i := 100 div 5;
  578.   j := i div 10;
  579.   j := i div j;
  580.   if j<>10 then
  581.     begin
  582.       write('*** Division failed, ');
  583.       writeln(j,' instead of 10');
  584.       errors := errors+1;
  585.     end;
  586.  
  587.   i := 102 mod 15;
  588.   j := i mod 7;
  589.   j := i mod j;
  590.   if j<>2 then
  591.     begin
  592.       write('*** MOD failed, ');
  593.       writeln(j,' instead of 2');
  594.       errors := errors+1;
  595.     end;
  596.  
  597.   i := 10;
  598.   j := i + 7;
  599.   j := (j - i) * (i - 2 * j);
  600.   if j<>-168 then
  601.     begin
  602.       write('*** Hierarchy failed, ');
  603.       writeln(j,' instead of -168');
  604.       errors := errors+1;
  605.     end;
  606.  
  607.   writeln('    Floating point arithmetic tests');
  608.   x := 1.0 / 3.0;
  609.   x := x * 3.0;
  610.   y := 1.0 - x;
  611.   if y=0.0 then
  612.     i := 99
  613.   else
  614.     a := round(-ln(y) / ln(10.0));
  615.   writeln('      Internal accuracy (digits): ',a:2);
  616.   x := 2.0 + 3.0;
  617.   y := x + 10.2;
  618.   y := y + x;
  619.   if y<>20.2 then
  620.     begin
  621.       write('*** Addition failed, ');
  622.       writeln(y,' instead of 2.0200E+01');
  623.       errors := errors+1;
  624.     end;
  625.  
  626.   x := 20.0 - 8.7;
  627.   y := x - 10.3;
  628.   y := x - y;
  629.   if y<>10.3 then
  630.     begin
  631.       write('*** Subtraction failed, ');
  632.       writeln(y,' instead of 1.0300E+01');
  633.       errors := errors+1;
  634.     end;
  635.  
  636.   x := 2.0 * 3.0;
  637.   y := x * 4.0;
  638.   y := y * x;
  639.   if y<>144.0 then
  640.     begin
  641.       write('*** Multiplication failed, ');
  642.       writeln(y,' instead of 1.4400E+02');
  643.       errors := errors+1;
  644.     end;
  645.  
  646.   x := 100.0 / 5.0;
  647.   y := x / 10.0;
  648.   y := x / y;
  649.   if y<>10.0 then
  650.     begin
  651.       write('*** Division failed, ');
  652.       writeln(y,' instead of 1.0000E+01');
  653.       errors := errors+1;
  654.     end;
  655.  
  656.   x := 10.0;
  657.   y := x + 7.0;
  658.   y := (y - x) * (x - 2.0 * y);
  659.   if y<>-168.0 then
  660.     begin
  661.       write('*** Hierarchy failed, ');
  662.       writeln(y,' instead of -1.6800E+02');
  663.       errors := errors+1;
  664.     end;
  665.  
  666.   x := 5;
  667.   i := 10;
  668.   y := i + 15 / x;
  669.   j := trunc( 7 + x / 2 - 0.8 );
  670.   if (y<>13.0) OR (j<>8) then
  671.     begin
  672.       write('*** Mixed mode arithmetic failed, ');
  673.       writeln(y,', ',j,' instead of 13.0, 8');
  674.       errors := errors+1;
  675.     end;
  676.  
  677.   writeln('    Log/Trig Function tests');
  678.   e := 1.0;
  679.   for i:=1 to (a-1) do
  680.     e := e * 10.0;        { compute the error multiplier }
  681.  
  682.   x := exp(1.0);
  683.   y := ln(x);
  684.   x := abs(1.0 - y) * e;  { compute the maximum allowable error }
  685.   if x>0.5 then
  686.     begin
  687.       write('*** Function exp(x) or ln(x) failed, ');
  688.       writeln(y,' instead of 1.0000E+00');
  689.       errors := errors+1;
  690.     end;
  691.  
  692.   y := sqr(sin(1.0)) + sqr(cos(1.0));
  693.   x := abs(1.0 - y) * e;  { compute the maximum allowable error }
  694.   if x>0.5 then
  695.     begin
  696.       write('*** Function sin(x) or cos(x) failed, ');
  697.       writeln(y,' instead of 1.0000E+00');
  698.       errors := errors+1;
  699.     end;
  700.  
  701.   x := sin(1.0) / cos(1.0);
  702.   y := arctan(x);
  703.   x := abs(1.0 - y) * e;  { compute the maximum allowable error }
  704.   if x>0.5 then
  705.     begin
  706.       write('*** Function arctan(x) failed, ');
  707.       writeln(y,' instead of 1.0000E+00');
  708.       errors := errors+1;
  709.     end;
  710.  
  711.  
  712.   writeln;
  713.   write('  Enter "C" <return> to continue');
  714.   read(c);
  715.   writeln;
  716.   writeln;
  717.  
  718.   writeln('  Control Structure testing');
  719.   writeln('    Nested IF structure tests');
  720.   a := 99;
  721.   i := 10;
  722.   j := 25;
  723.   x := 13.5;
  724.   y := -45.0;
  725.   if i<j then
  726.     if x>y then
  727.       if i>17 then
  728.         a := 3
  729.       else
  730.         a := 0
  731.     else
  732.       a := 2
  733.   else
  734.     a := 1;
  735.   if a<>0 then
  736.     begin
  737.       write('*** Nested IF structure failed, ');
  738.       writeln(a,' instead of 0');
  739.       errors := errors+1;
  740.     end;
  741.  
  742.   writeln('    FOR structure tests');
  743.   a := 0;
  744.   for i:=0 to 10 do
  745.     begin
  746.       ain[i] := i+1;
  747.       a := a+1;
  748.     end;
  749.   if a<>11 then
  750.     begin
  751.       write('*** FOR (to) integer index count failed, ');
  752.       writeln(a,' instead of 11');
  753.       errors := errors+1;
  754.     end;
  755.   a := 0;
  756.   for i:=10 downto 0 do
  757.     begin
  758.       if ain[i]<>(i+1) then
  759.         begin
  760.           write('*** Array assignment failed at position ',i,', ');
  761.           writeln(ain[i],' instead of ',i+1);
  762.           errors := errors+1;
  763.         end;
  764.       a := a+1;
  765.     end;
  766.   if a<>11 then
  767.     begin
  768.       write('*** FOR (downto) integer index count failed, ');
  769.       writeln(a,' instead of 11');
  770.       errors := errors+1;
  771.     end;
  772.  
  773.   a := 0;
  774.   for c:='c' to 'p' do
  775.     a := a+1;
  776.   if a<>14 then
  777.     begin
  778.       write('*** FOR (to) character index count failed, ');
  779.       writeln(a,' instead of 14');
  780.       errors := errors+1;
  781.     end;
  782.   a := 0;
  783.   for c:='r' downto 'a' do
  784.     a := a+1;
  785.   if a<>18 then
  786.     begin
  787.       write('*** FOR (downto) character index count failed, ');
  788.       writeln(a,' instead of 18');
  789.       errors := errors+1;
  790.     end;
  791.  
  792.   writeln('    Nested FOR structure tests');
  793.   a := 0;
  794.   for i:=1 to 25 do
  795.     for j:= -5 to 4 do
  796.       a := a + 1;
  797.   if a<>250 then
  798.     begin
  799.       write('*** Nexted FOR index count failed, ');
  800.       writeln(a,' instead of 250');
  801.       errors := errors+1;
  802.     end;
  803.  
  804.   writeln('    CASE structure tests');
  805.   i := 5;
  806.   j := 99;
  807.   case i of
  808.     1 : j := 1;
  809.     2 : j := 2;
  810.     3 : j := 3;
  811.     4 : j := 4;
  812.     5 : j := 5;
  813.     6 : j := 6;
  814.   end;
  815.   if j<>5 then
  816.     begin
  817.       write('*** CASE statement (integer) failed, ');
  818.       writeln(j,' instead of 5');
  819.       errors := errors+1;
  820.     end;
  821.  
  822.   c := 'g';
  823.   case c of
  824.     'a' : j := 1;
  825.     'c' : j := 2;
  826.     'g' : j := 3;
  827.     'z' : j := 4;
  828.   end;
  829.   if j<>3 then
  830.     begin
  831.       write('*** CASE statement (character) failed, ');
  832.       writeln(j,' instead of 3');
  833.       errors := errors+1;
  834.     end;
  835.  
  836.   writeln('    Nested CASE structure tests');
  837.   i := 7;
  838.   j := 5;
  839.   a := 99;
  840.   case i of
  841.     1 : a := 10;
  842.     7 : case j of
  843.           1 : a := 21;
  844.           9 : a := 22;
  845.           5 : a := 23;
  846.         end;
  847.     9 : a := 30;
  848.   end;
  849.   if a<>23 then
  850.     begin
  851.       write('*** Nested CASE statement failed, ');
  852.       writeln(a,' instead of 23');
  853.       errors := errors+1;
  854.     end;
  855.  
  856.   writeln('    WHILE structure tests');
  857.   i := 100;
  858.   while (i>0) and (i<101) do
  859.     i := i-1;
  860.   if i<>0 then
  861.     begin
  862.       write('*** WHILE statement failed, ');
  863.       writeln(i,' instead of 0');
  864.       errors := errors+1;
  865.     end;
  866.  
  867.   writeln('    Nested WHILE structure tests');
  868.   i := 200;
  869.   j := 0;
  870.   a := 0;
  871.   while (i>5) and (i<201) do
  872.     begin
  873.       i := i-1;
  874.       j := j+1;
  875.       while (i mod 5) <> 1 do
  876.         begin
  877.           a := a+1;
  878.           i := i-2;
  879.         end;
  880.     end;
  881.   if (i<>1) or (j<>39) or (a<>80) then
  882.     begin
  883.       write('*** Nested WHILE statement failed, ');
  884.       writeln(i,', ',j,', ',a,' instead of 1, 39, 80');
  885.       errors := errors+1;
  886.     end;
  887.  
  888.   writeln('    REPEAT structure tests');
  889.   i := 450;
  890.   repeat
  891.    i := i-1;
  892.   until (i<250) or (i>450);
  893.   if i<>249 then
  894.     begin
  895.       write('*** REPEAT statement failed, ');
  896.       writeln(i,' instead of 249');
  897.       errors := errors+1;
  898.     end;
  899.  
  900.   writeln('    Nested REPEAT structure tests');
  901.   i := 450;
  902.   j := 0;
  903.   a := 0;
  904.   repeat
  905.    i := i-1;
  906.    j := j+1;
  907.    repeat
  908.      i := i-3;
  909.      a := a+1;
  910.    until odd(i);
  911.   until (i<100) or (i>450);
  912.   if (i<>99) or (j<>87) or (a<>88) then
  913.     begin
  914.       write('*** Nested REPEAT statement failed, ');
  915.       writeln(i,', ',j,', ',a,' instead of 99, 87, 88');
  916.       errors := errors+1;
  917.     end;
  918.  
  919.  
  920.   writeln;
  921.   write('  Enter "C" <return> to continue');
  922.   read(c);
  923.   writeln;
  924.   writeln;
  925.  
  926.   writeln('  Procedure and function testing');
  927.   writeln('    Procedure call tests');
  928.   i := 0;
  929.   x := 10.0;
  930.   write('      Procedure 1 ');
  931.   ptest1;
  932.   if i<>0 then
  933.     begin
  934.       writeln('*** Integer local variables damaging globals');
  935.       errors := errors+1;
  936.     end;
  937.   if x<>10.0 then
  938.     begin
  939.       writeln('*** Real local variables damaging globals');
  940.       errors := errors+1;
  941.     end;
  942.  
  943.   j := 25;
  944.   y := 25.0;
  945.   write('      Procedure 2 ');
  946.   ptest2(10,10.0,j,y);
  947.   if j<>24 then
  948.     begin
  949.       writeln('*** Call by reference integer not returned correctly');
  950.       errors := errors+1;
  951.     end;
  952.   if y<>24.0 then
  953.     begin
  954.       writeln('*** Call by reference real not returned correctly');
  955.       errors := errors+1;
  956.     end;
  957.  
  958.   writeln('      Recursive procedure test (5..0)');
  959.   write('      ');
  960.   i := 5;
  961.   ptest3(i);
  962.   writeln;
  963.   if i<>5 then
  964.     begin
  965.       writeln('*** Call by value in recursive test failed');
  966.       errors := errors+1;
  967.     end;
  968.  
  969.   writeln('    Function call tests');
  970.   i := 0;
  971.   x := 75.0;
  972.   write('      Function 1 ');
  973.   i := ftest1(i,x);
  974.   if i<>100 then
  975.     begin
  976.       writeln('*** Function not returning correct value');
  977.       errors := errors+1;
  978.     end;
  979.  
  980.   writeln('      Recursive function  test (0..5)');
  981.   write('      ');
  982.   i := 5;
  983.   j := ftest2(i);
  984.   writeln;
  985.   if i<>5 then
  986.     begin
  987.       writeln('***   Call by value in recursive function test failed');
  988.       errors := errors+1;
  989.     end;
  990.   if j<>10 then
  991.     begin
  992.       writeln('***   Function not returning correct value during recursion');
  993.       errors := errors+1;
  994.     end;
  995.  
  996.  
  997.   writeln;
  998.   writeln('  Testing complete');
  999.   if errors > 0 then
  1000.     writeln(errors, ' Error(s) Found')
  1001.   else
  1002.     writeln('  No Errors Found')
  1003.  
  1004. end.
  1005.